package models

import (
	valid "github.com/go-ozzo/ozzo-validation"
	//"fmt"
	//"reflect"
	"titargo/types"
)


const (
	USER_POWER_USER   = 0
	USER_POWER_ADMIN  = 1

	USER_ON_JOB     = 1
	USER_NOT_ON_JOB = 0
)

type User struct {
	Id          int    `xorm:"not null pk autoincr INT(10)" form:"id" json:"id"`
	Username    string `xorm:"not null comment('管理员名称') VARCHAR(255)" form:"username" json:"username"`
	Password    string `xorm:"not null comment('密码') VARCHAR(255)" form:"password" json:"password"`
	Name        string `xorm:"not null comment('姓名') VARCHAR(255)" form:"name" json:"name"`
	Mobile      string `xorm:"not null comment('手机号') VARCHAR(255)" json:"mobile"`
	Phone       string `xorm:"not null comment('电话') VARCHAR(50)" json:"phone"`
	Email       string `xorm:"not null comment('邮箱') VARCHAR(255)" json:"email"`
	Sex         string `xorm:"not null comment('性别') VARCHAR(255)" json:"sex"`
	CreatedAt   types.TimeType    `xorm:"created not null comment('创建时间戳') INT(11)" json:"created_at"`
	UpdatedAt   types.TimeType    `xorm:"updated not null comment('修改时间戳') INT(11)" json:"updated_at"`
}

func (u User) Validate() error {
	err := valid.ValidateStruct(&u,
		valid.Field(&u.Username, valid.Required.Error("用户名不能为空")),
		valid.Field(&u.Password, valid.Required.Error("密码不能为空")),
		valid.Field(&u.Name, valid.Required.Error("姓名不能为空")),
		valid.Field(&u.Sex, valid.Required.Error("性别不能为空")),
	)

	return err
}
